package shayu.order.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import shayu.order.entity.OrderEntity;
import shayu.order.service.OrderService;
import shayu.order.vo.OrderSubmitVo;
import shayu.order.vo.SumbitOrderResponseVo;

@Controller
public class OrderWebController {
    @Autowired
    private OrderService orderService;

    // 获取订单信息
    public String getOrder() {

        return "";

    }

    // 下单功能
    @PostMapping("/sumbitOrder")
    public String submitOrder(OrderSubmitVo vo, Model model) {
        SumbitOrderResponseVo responseVo = orderService.sumbitOrder(vo);
        // 下单：去创建订单，验令牌，验价格，锁库库存
        //  下单失败就回到订单页面继续重新确认页面订单信息
        System.out.println("订单提交的数据" + responseVo);
        if (responseVo.getCode() == 0) {
            // 下单成功来到支付选择页
            model.addAttribute("submitOrderResp",responseVo);
            return "pay";
        } else {
            return "redirect://http:localhost:8052/toTrade";
        }
    }

}
